home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1374 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.6 KB  |  62 lines

  1. Path: news.cis.nctu.edu.tw!usenet
  2. From: terryt@mcs.com (Terry Trippany)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Function body banned in .H file - Can I still inline?
  5. Date: 10 Jan 1996 17:45:46 GMT
  6. Organization: STR/Baxter Labs
  7. Message-ID: <4d0u0a$gc7@news.cis.nctu.edu.tw>
  8. References: <4d0ir0$68e@newsroom.hitc.com>
  9. NNTP-Posting-Host: @159.198.73.111
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-Newsreader: WinVN 0.99.7
  13.  
  14. In article <4d0ir0$68e@newsroom.hitc.com>, cruegger@eos.hitc.com says...
  15. >
  16. >I am not permitted to put any function bodies into the .H file for a class.
  17. >Question:
  18. >  I would still like to make the small accessor routines inline. What
  19. >  is my recourse, if any?
  20. >
  21. >Thanks,
  22. >Chris
  23. >
  24. Hi Chris,
  25.  
  26.   If you want to make a function inline without putting the source in the 
  27. header then you can use the inline keyword.  BE AWARE that this is just a hint 
  28. to the compiler and it may or may not treat it as inline depending on which 
  29. compiler you use.
  30.  
  31. eg: 
  32. // file foo.hpp
  33.  
  34. class Foo
  35. {
  36.   void myFunc();
  37. }
  38.  
  39. // file foo.cpp
  40.  
  41. inline void Foo::myFunc() { ... }
  42.  
  43. You could also specify the inline keyword in the declaration file if that's 
  44. where you would like to put it.
  45.  
  46.  
  47. Either way some linkers can treat non-inlined functions that are declared as 
  48. inline (ie. they don't inline the function for some reason) as if they had 
  49. been declared static.  Thus increasing code size if the compiler treats it 
  50. this way as opposed to ignoring it altogether.  
  51.  
  52. Also, you should turn off inline functions for debugging.
  53.  
  54. Later,
  55.  
  56. Terry Trippany
  57. Strategic Technology Resources
  58. Chicago, IL.
  59.  
  60. terryt@mcs.com
  61.  
  62.